package com.fyp.speachrecognition;

import com.fyp.database.DataProvider;
import com.fyp.database.User;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class RegistrationActivity extends Activity{
	
	private DataProvider dp;
	 EditText username, password,email;
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);

		setContentView(R.layout.registration_form);
		Log.v("Activity", "Login Activity Started");
		TextView loginScreen = (TextView) findViewById(R.id.link_to_login);
		Button register  = (Button) findViewById(R.id.btnRegister);
		username=(EditText) findViewById(R.id.reg_fullname);
		 password=(EditText) findViewById(R.id.reg_password);
		 email=(EditText) findViewById(R.id.reg_email);
		dp = new DataProvider(this);
	   
	    register.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				
				if(!(username.getText().toString().equals(""))  &&   !(password.getText().toString().equals("")))
				{
					 dp.open();
					String[] values = new String[] { username.getText().toString(), email.getText().toString(), password.getText().toString() };
					
							Log.v("Register", values[0]+"---"+values[1]);
					User u;
					u=dp.createUser(values);
					if(u!=null)
						Toast.makeText(getApplicationContext(), "Registeration Successfull !!!", Toast.LENGTH_LONG).show();
					else
						Toast.makeText(getApplicationContext(), "Registeration Failed !!!", Toast.LENGTH_LONG).show();
					
					 dp.close();
				}
				else
					Toast.makeText(getApplicationContext(), "Registeration Failed! Give Username Or Password", Toast.LENGTH_LONG).show();
				
			}
		});
        loginScreen.setOnClickListener(new View.OnClickListener() {
 
            public void onClick(View arg0) 
            {
                                
                finish();
            }
        });

	};
	@Override
	  protected void onResume() {
	    
	    super.onResume();
	  }

	  @Override
	  protected void onPause() {
	  
	    super.onPause();
	  }

}
